//
//  DFViewController.m
//  DFKit
//
//  Created by chenrj90 on 04/08/2017.
//  Copyright (c) 2017 chenrj90. All rights reserved.
//

#import "DFViewController.h"
#import <DFKit/DFKit.h>
#import <DFKit/DFKitShare.h>
#import <DFKit/DFKitAnalyze.h>
#import "DFTestPageController.h"
#import "DFSinglePageController.h"
#import "DFHudTestController.h"

@interface DFViewController ()<NSURLConnectionDataDelegate>

@end

@implementation DFViewController

+ (void)load {
    [DFRouter registerURL:DF_DEMO_TEST forViewController:[self class]];
}

- (NSString *)title {
    return @"测试";
}

- (NSInteger)tabbarIndex {
    return 1;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *view = DFMakeViewWithBackgroundColor([UIColor df_randomColor]);
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.mas_topLayoutGuideBottom);
    }];
    [view df_setIntrinsicContentSizeBlock:^CGSize(UIView *view) {
        return CGSizeMake(200, 200);
    }];
    [view addTapGestureRecognizer:^(UITapGestureRecognizer *recognizer, NSString *gestureId) {
//        [DFShareManager shareWebPage:@"http://www.baidu.com"
//                               title:@"度娘"
//                                desc:@"度娘懂你"
//                          thumbImage:@"https://mobile.umeng.com/images/pic/home/social/img-1.png"
//                        platformType:DFSharePlatformTypeWechatSession
//                          completion:^(id result, NSError *error) {
//                              NSLog(@"完成:%@ %@", result, error);
//                          }];
//        
//        [DFShareManager shareImage:@"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1491811536&di=5396a7b0fa4f22cd4deec7f575f5b032&src=http://img3.duitang.com/uploads/item/201607/31/20160731173132_ua8yd.thumb.224_0.jpeg"
//                             title:@"title"
//                              desc:@"desc"
//                        thumbImage:@"https://mobile.umeng.com/images/pic/home/social/img-1.png"
//                      platformType:DFSharePlatformTypeWechatSession
//                        completion:^(id result, NSError *error) {
//                            NSLog(@"完成:%@ %@", result, error);
//                        }];
        
        UIViewController *v = [[DFHudTestController alloc] init];
        v.df_shouldHideNavigationBar = YES;
        [self.navigationController pushViewController:v animated:YES];
    }];
    [view df_expandTouchAreaByInsets:UIEdgeInsetsMake(-10, -10, 0, -10)];
    
    UILabel *label = DFMakeLabel(@"Hello DFRZW", [UIColor df_randomColor], [UIFont systemFontOfSize:16]);
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_bottom);
        make.centerX.equalTo(self.view);
    }];
    
    label.layer.borderWidth = DF_ONE_PIXEL;
    label.layer.borderColor = label.textColor.CGColor;
    [label df_setIntrinsicContentSizeBlock:^CGSize(UIView *view) {
        CGSize origin = [view df_intrinsicContentSize];
        origin.width += 50;
        origin.height += 20;
        return origin;
    }];
    
    label.userInteractionEnabled = YES;
    
    [label addTapGestureRecognizer:^(UITapGestureRecognizer *recognizer, NSString *gestureId) {
        DFTestPageController *vc = [[DFTestPageController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
    [label df_expandTouchAreaByInsets:UIEdgeInsetsMake(-10, -10, -20, -10)];
    
    self.df_shouldHideNavigationBar = YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [DFAnalyzeManager beginLogPageWithName:@"Main"];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [DFAnalyzeManager endLogPageWithName:@"Main"];
}

@end
